YAHOO.namespace("CSW2.yuitest");

// Test Cases 
YAHOO.CSW2.yuitest.Map_loadConfig = new YAHOO.tool.TestCase({
 
    name: "test_Map_loadConfig",
 
    setUp : function () {
    },
 
    tearDown : function () {
    },

    test_Map_loadConfig  : function () {

		var cwn2Map = new CWN2.Map('testMap');
		cwn2Map.loadConfig();
		YAHOO.util.Assert.areEqual(cwn2Map.projection, "EPSG:900913", "Proiezione dovrebbe essere 'EPSG:900913'");
    },
	
    test_Map_loadLayer  : function () {

		var cwn2Map = new CWN2.Map('testMap');
		var layerConfig = CWN2.configuration.layers[0]; 
		cwn2Map.loadLayer(layerConfig);
		YAHOO.util.Assert.areEqual(cwn2Map.layers[0].name, layerConfig.name, "Nome layer OL dovrebbe essere uguale al nome del layerConfig");
    },
	
     test_Map_loadControl  : function () {

		var cwn2Map = new CWN2.Map('testMap');
		var controlConfig = CWN2.configuration.olControls[0]; 
		cwn2Map.loadControl(controlConfig);
		var  controls = cwn2Map.getControlsByClass("OpenLayers.Control.LayerSwitcher");
		YAHOO.util.Assert.areNotEqual(controls.length, 0, "Controlli in mappa devono essere diversi da 0");
    },
 
     test_Map_initControl  : function () {

		var cwn2Map = new CWN2.Map('testMap');
		var controlConfig = CWN2.configuration.olControls; 
		cwn2Map.initControls(controlConfig);
		var  mapControls = cwn2Map.controls;
		YAHOO.util.Assert.areEqual(mapControls.length, 6, "Controlli in mappa devono essere 6");
    }
 
 });
 
 // Test Suite
YAHOO.CSW2.yuitest.Map_suite = new YAHOO.tool.TestSuite("Map Test Suite"); 
YAHOO.CSW2.yuitest.Map_suite.add(YAHOO.CSW2.yuitest.Map_loadConfig); 
YAHOO.CSW2.yuitest.Map_suite.add(YAHOO.CSW2.yuitest.Map_loadLayer);  
YAHOO.CSW2.yuitest.Map_suite.add(YAHOO.CSW2.yuitest.Map_loadControl); 
YAHOO.namespace("CSW2.yuitest");

// Test Cases 
YAHOO.CSW2.yuitest.json_load = new YAHOO.tool.TestCase({
 
    name: "json_load",
 
    setUp : function () {
    },
 
    tearDown : function () {
    },

    test_json_load_sync : function () {
		var url = 'config/test.json';
		var obj = CWN2.json.load(url,true);
		YAHOO.util.Assert.isNotNull(obj.name, "oggetto non deve essere null");
    }
 
 });
 
 // Test Suite
YAHOO.CSW2.yuitest.json_suite = new YAHOO.tool.TestSuite("json Test Suite"); 
YAHOO.CSW2.yuitest.json_suite.add(YAHOO.CSW2.yuitest.json_load); 
 
YAHOO.namespace("CSW2.yuitest");

// Test Cases 
YAHOO.CSW2.yuitest.controlFactory_createControl = new YAHOO.tool.TestCase({
 
    name: "test_controlFactory_createControl",
 
    setUp : function () {
		
    },
 
    tearDown : function () {
    },

    test_controlFactory_createControl  : function () {
		var config = CWN2.configuration;
		var controlConfig = config.olControls[0];
		var control = CWN2.controlFactory.createControl(controlConfig);
		YAHOO.util.Assert.isInstanceOf(OpenLayers.Control.LayerSwitcher, control, "Controllo deve essere di tipo LayerSwitcher.");
    }
 
 });
 
 // Test Suite
YAHOO.CSW2.yuitest.controlFactory_suite = new YAHOO.tool.TestSuite("controlFactory Test Suite"); 
YAHOO.CSW2.yuitest.controlFactory_suite.add(YAHOO.CSW2.yuitest.controlFactory_createControl); 
 
YAHOO.namespace("CSW2.yuitest");

// Test Cases 
YAHOO.CSW2.yuitest.actionFactory_createAction = new YAHOO.tool.TestCase({
 
    name: "test_actionFactory_createAction",
 
    setUp : function () {
		
    },
 
    tearDown : function () {
    },

    test_actionFactory_createAction  : function () {

		var actionConfig = CWN2.configuration.toolbar.itemGroups[0].items[0];
		var cwn2Map = new CWN2.Map('testMap');

		var action = CWN2.actionFactory.createAction(actionConfig,cwn2Map);

		YAHOO.util.Assert.isInstanceOf(GeoExt.Action, action, "Action deve essere di tipo GeoExt.Action");

    }
 
 });
 
 // Test Suite
YAHOO.CSW2.yuitest.actionFactory_suite = new YAHOO.tool.TestSuite("actionFactory Test Suite"); 
YAHOO.CSW2.yuitest.actionFactory_suite.add(YAHOO.CSW2.yuitest.actionFactory_createAction); 
 
YAHOO.namespace("CSW2.yuitest");

// Test Cases 
YAHOO.CSW2.yuitest.layerFactory_createLayer = new YAHOO.tool.TestCase({
 
    name: "test_layerFactory_createLayer",
 
    setUp : function () {
		//CWN2.configuration.load('config/test.json');
    },
 
    tearDown : function () {
    },

    test_layerFactory_createLayer  : function () {
		var config = CWN2.configuration;
		var layerConfig = CWN2.configuration.layers[0];
		var layer = CWN2.layerFactory.createLayer(layerConfig);
		YAHOO.util.Assert.areEqual(layer.name, layerConfig.name, "Nome layer OL dovrebbe essere uguale al nome del layerConfig");
    }
 
 });
 
 // Test Suite
YAHOO.CSW2.yuitest.layerFactory_suite = new YAHOO.tool.TestSuite("layerFactory Test Suite"); 
YAHOO.CSW2.yuitest.layerFactory_suite.add(YAHOO.CSW2.yuitest.layerFactory_createLayer); 
 
YAHOO.namespace("CSW2.yuitest");

// Test Cases 
YAHOO.CSW2.yuitest.configuration_1 = new YAHOO.tool.TestCase({
 
    name: "configuration_1",
 
    setUp : function () {
    },
 
    tearDown : function () { 
    },

    test_configuration_load : function () {
		CWN2.configuration.name = null;
		CWN2.configuration.load('config/test.json');
		YAHOO.util.Assert.isNotNull(CWN2.configuration.name, "Nome non deve essere null");
    },
	
    test_configuration_getLayerConfigByName : function () {
		var layerName = "Google Stradario";
		var layerConfig = CWN2.configuration.getLayerConfigByName(layerName);
		YAHOO.util.Assert.areEqual(layerConfig.name, "Google Stradario", "Nome layer dovrebbe essere 'Google Stradario'");
    }
 
 
 });
 
 // Test Suite
YAHOO.CSW2.yuitest.configuration_suite = new YAHOO.tool.TestSuite("configuration Test Suite"); 
YAHOO.CSW2.yuitest.configuration_suite.add(YAHOO.CSW2.yuitest.configuration_1); 
 
YAHOO.namespace("CSW2.yuitest");

// Test Cases 
YAHOO.CSW2.yuitest.openlayersExt_loadGeoJSON = new YAHOO.tool.TestCase({
 
    name: "openlayersExt_loadGeoJSON",
 
    setUp : function () {
    },
 
    tearDown : function () { 
    },

    test_openlayersExt_loadGeoJSON : function () {
		// carico la mappa
		var cwn2Map = new CWN2.Map('pippo');
		cwn2Map.loadConfig();

		// definisco il geoJSON
		// definizione di un oggetto contenente un GeoJSON
		var GeoJSON = { "type": "FeatureCollection",
		  "features": [
			    { "type": "Feature",
			      "geometry": {"type": "Point", "coordinates": [8.0, 44.5]},
			      "properties": {
				  	"id": "ID1",
				  	"label": "Label 1"
					}
			      },
			    { "type": "Feature",
			      "geometry": {"type": "Point", "coordinates": [9.0, 44.5]},
			      "properties": {
				  	"id": "ID2",
				  	"label": "Label 2"
					}
			      },
			    { "type": "Feature",
			      "geometry": {"type": "Point", "coordinates": [8.5, 44.5]},
			      "properties": {
				  	"id": "ID1",
				  	"label": "Label 3"
				  }
			    }
		     ]
		   };
		// carico il geoJson
		var layer = cwn2Map.getLayersByName('GeoJSON')[0];
		layer.loadGeoJSON(GeoJSON);
		YAHOO.util.Assert.areEqual(layer.features.length, 3, "Le feature caricate devono essere 3");
    }
 
 
 });
 
 // Test Suite
YAHOO.CSW2.yuitest.openlayersExt_suite = new YAHOO.tool.TestSuite("openlayersExt Test Suite"); 
YAHOO.CSW2.yuitest.openlayersExt_suite.add(YAHOO.CSW2.yuitest.openlayersExt_loadGeoJSON); 
 
